import QtQuick 2.12
import QtQuick.Controls 2.5
import QtQuick.Window 2.12
import QtQuick.Layouts 1.0
import ModelListModel 1.0
import Log 1.0
import "qrc:/CustomComponent"


Rectangle {
    id: root
    property alias currentIndex: viewer.currentIndex
    property var displayText
    property var model
    signal activated(int index)

    property color _normal_color: "transparent"
    property color _hover_color: Theme.item_hover_write_color
    property color _checked_color: "#e0eaff"

    MouseArea {
        anchors.fill: parent
        hoverEnabled: true
        onEntered: {}
        onExited: {}
        onClicked: { popuper.visible = !popuper.visible }
    }

    Popup {
        id: popuper
        closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent

        background: Rectangle{
            color: "white"
            radius: 4
            border.width: 1
            border.color: Theme.border_normal_color

            ListView {
                id: viewer
                Layout.fillWidth: true
                Layout.fillHeight: true
                Layout.leftMargin: 1
                Layout.rightMargin: 1
                property var collapsed: ({})
                ScrollBar.vertical: ScrollBar{}
                model: root.model
                highlight: Rectangle { color: root._checked_color }
                highlightMoveDuration: 0
                clip: true

                //选项
                delegate: Rectangle{
                    id: item
                    implicitWidth: viewer.width
                    implicitHeight: 24
                    color: "transparent"

                    //文本内容
                    CusText {
                        text: model.displayText
                        anchors.left: parent.left
                        anchors.right: parent.right
                        anchors.verticalCenter: parent.verticalCenter
                        anchors.leftMargin: 6
                        elide: Text.ElideRight
                        color: Theme.text_color

                        font.pixelSize: Theme.font_size_13
                    }

                    MouseArea{
                        id: mouseArea
                        hoverEnabled: true
                        anchors.fill: parent
                        onClicked: { viewer.currentIndex = index }
                        onEntered: { }
                        onExited: { }
                    }
                }
            }
        }
    }
}


